<template>
  <div class="_wz_cent_main">
    <div class="_wz_deptConfiguration" style="    padding: 30px 0 0 0;">
      <div style="max-width: 1000px;margin: auto;min-width:800px;">

        <Form :model="formData" label-position="right" :label-width="140">
          <FormItem label="运输企业">
            {{!!formData.deptName?formData.deptName:'--'}}
          </FormItem>
          <Row>
            <i-col span="12">
              <FormItem label="运输类型">
                {{!!formData.deptTransportName?formData.deptTransportName:'--'}}
              </FormItem>
            </i-col>
            <i-col span="12">
              <FormItem label="剩余授权次数">
                {{!!formData.configAuthNumber?formData.configAuthNumber:'0'}}条
              </FormItem>
            </i-col>
          </Row>


          <Row>
            <Divider>基本信息</Divider>

            <i-col span="24">
              <i-col span="12">
                <FormItem label="学员自动审核">
                  <i-switch v-model.number="formData.configDriverVerifyFlag" :false-value="0" :true-value="1">
                    <span slot="open">开</span>
                    <span slot="close">关</span>
                  </i-switch>
                </FormItem>
              </i-col>
              <i-col span="12">
                <FormItem label="培训自动授权">
                  <i-switch v-model.number="formData.configDriverAuthFlag" :false-value="0" :true-value="1">
                    <span slot="open">开</span>
                    <span slot="close">关</span>
                  </i-switch>
                </FormItem>
              </i-col>
            </i-col>
<!--            <i-col span="12">-->
<!--              <FormItem label="车辆数据同步">-->
<!--                <i-switch v-model.number="formData.configVehicleAsyncAutoFlag" :false-value="0" :true-value="1">-->
<!--                  <span slot="open">开</span>-->
<!--                  <span slot="close">关</span>-->
<!--                </i-switch>-->
<!--              </FormItem>-->
<!--            </i-col>-->
            <i-col span="12">
              <FormItem label="人员合同签署">
                <i-switch v-model.number="formData.configDriverContractNeedFlag" :false-value="0" :true-value="1">
                  <span slot="open">开</span>
                  <span slot="close">关</span>
                </i-switch>
                <Tooltip content="从业人员是否必须签署合同、承诺书、责任状、告知书" max-width="200">
                  <Icon type="md-warning" />
                </Tooltip>
              </FormItem>
            </i-col>
          </Row>
          <Row>
            <Divider>数据订阅</Divider>
            <i-col span="12">
              <FormItem label="培训课程订阅">
                <i-switch v-model.number="formData.configTrainSubscriptionFlag" :false-value="0" :true-value="1">
                  <span slot="open">开</span>
                  <span slot="close">关</span>
                </i-switch>
              </FormItem>
            </i-col>
            <i-col span="12">
              <FormItem label="考试测验订阅">
                <i-switch v-model.number="formData.configExamSubscriptionFlag" :false-value="0" :true-value="1">
                  <span slot="open">开</span>
                  <span slot="close">关</span>
                </i-switch>
              </FormItem>
            </i-col>
          </Row>
          <div>
            <Divider>数据初始化</Divider>
            <Button type="primary" @click="deptDataInit('/safety/drivingLog/drivingLogCheckInit','行车检查项')" style="margin: 0 0 10px 0;">行车检查项初始化</Button>
            <Button type="primary" @click="deptDataInit('/safety/drivingLog/drivingLogRemindInit','行车安全问询')" style="margin: 0 0 10px 0;">行车安全问询初始化</Button>
          </div>

          <div class="demo-drawer-footer">
            <Button type="primary" @click="addSubmit">保存</Button>
          </div>
        </Form>
      </div>
    </div>
    <Spin size="large" fix v-if="spinShow"></Spin>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        spinShow:false,//本页加载
        formData: {
          configInsuranceRemindDay:0,
          configInsuranceSmsSendDay:0,
          configInsuranceSmsSend:0,
          configAnnualInspectRemindDay:0,
          configAnnualInspectSmsSendDay:0,
          configAnnualInspectSmsSend:0,
          configOperationCertificateRemindDay:0,
          configOperationCertificateSmsSendDay:0,
          configOperationCertificateSmsSend:0,
          configMaintainRemindDay:0,
          configMaintainSmsSendDay:0,
          configMaintainSmsSend:0,
          configTrailerVesselTaxRemindDay:0,
          configTrailerVesselTaxSmsSendDay:0,
          configTrailerVesselTaxSmsSend:0,
          configTrainSubscriptionFlag:0,
          configExamSubscriptionFlag:0,
          configDriverVerifyFlag:0,
          configDriverAuthFlag:0,
          configMaterialSubscriptionFlag:0,// 课件授权使用
          configDriverContractNeedFlag:0,
        }
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;
      //企业配置
      that.spinShow = true;
      that.axios.post(that.apiUrl.webApi + "/core/dept/config/coreDeptConfigInfo",{deptUuid: JSON.parse(sessionStorage.getItem('loginData')).user.deptUuid}).then(res => {
        that.spinShow = false;
        if (!!res) {
          var data = JSON.parse(sessionStorage.getItem('loginData')).user;
          res.data.data.deptName = data.deptName;
          that.formData = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    methods: {//执行的方法
      addSubmit() {//新增修改提交
        let that = this;
        that.spinShow = true;
        that.axios.post(that.apiUrl.webApi + "/core/dept/config/coreDeptConfigSaveOrUpdate", that.formData).then(res => {
          that.spinShow = false;
          if (!!res) {
            that.$Message.success('保存成功');
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
      //初始化数据
      deptDataInit(url,name){
        let that = this;
        that.$Modal.confirm({
          title: '初始化提醒',
          content: '确定要初始化'+name+'数据？初始化将会清除您原有的数据，请谨慎操作。',
          onOk: () => {
            that.$Spin.show();//显示加载
            that.axios.post(that.apiUrl.webApi + url,{deptUuid:that.formData.deptUuid,deptTransportCode:that.formData.deptTransportCode}).then(res => {
              that.$Spin.hide();//显示加载
              if (!!res) {
                that.$Message.success('初始化完成');
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //点击取消
          }
        });
      },
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_deptConfiguration {
    width: 100%;
    height: 100%;
    background: #fff;
    overflow: auto;
  }

</style>
